home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Form / Sources / EditCmd.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.0 KB  |  198 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                EditCmd.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef EDITCMD_H
  11. #define EDITCMD_H
  12.  
  13. //----------------------------------------------------------------------------------------
  14. // Imported Classes
  15. //----------------------------------------------------------------------------------------
  16.  
  17. #ifndef FWCLPCMD_H
  18. #include "FWClpCmd.h"
  19. #endif
  20.  
  21. #ifndef FWCONTNT_H
  22. #include "FWContnt.h"
  23. #endif
  24.  
  25. #ifndef FWSELECT_H
  26. #include "FWSelect.h"
  27. #endif
  28.  
  29. #ifndef FWRECEVR_H
  30. #include "FWRecevr.h"
  31. #endif
  32.  
  33. #ifndef FWSTRING_H
  34. #include "FWString.h"
  35. #endif
  36.  
  37. //========================================================================================
  38. //    Forward Declaration
  39. //========================================================================================
  40.  
  41. class FW_CEditView;
  42. class FW_CFrame;
  43. class CEditViewSelection;
  44.  
  45. //========================================================================================
  46. //    class CEditViewCommand
  47. //========================================================================================
  48.  
  49. class CEditViewCommand : public FW_CClipboardCommand, public FW_MReceiver
  50. {
  51.   public:
  52.     FW_DECLARE_AUTO(CEditViewCommand)
  53.  
  54.     CEditViewCommand(Environment* ev, 
  55.                          ODCommandID commandID,
  56.                          FW_CFrame* frame, 
  57.                          FW_Boolean canUndo);
  58.  
  59.     virtual ~ CEditViewCommand();
  60.  
  61.     // ----- FW_CCommand API -----
  62.     virtual void         UndoIt(Environment* ev);
  63.     virtual void         RedoIt(Environment* ev);
  64.     virtual void         SaveUndoState(Environment* ev);
  65.     virtual void         SaveRedoState(Environment* ev);
  66.  
  67.     // ----- FW_CClipboardCommand API -----
  68.     virtual void        PreCommand(Environment* ev);
  69. //    virtual void         CommandDone(Environment* ev);
  70.  
  71.     // ----- FW_MReceiver API -----
  72.     void                 HandleNotification(Environment* ev, const FW_CNotification& notification);
  73.  
  74.     // ----- New API
  75.     void                 SetEditView(FW_CEditView* editView);
  76.     void                 SetSelection(CEditViewSelection* selection);
  77.     CEditViewSelection* GetSelection(Environment* ev) const;
  78.     
  79.   private:
  80.     void                 RemoveText(Environment* ev);
  81.     void                 RestoreText(Environment* ev);
  82.     void                 RemoveAndRestoreText(Environment* ev, FW_ByteCount bytesToRemove, 
  83.                             const FW_CString& textToRestore);
  84.  
  85.   private:
  86.     FW_Boolean            fOwnsSelection;    
  87.     FW_CEditView*        fEditView;
  88.     //--- Saved data for undo/redo
  89.     FW_CString            fPastedText;
  90.     FW_CString            fSavedText;        // original text (Paste command)
  91.     short                fStartOffset;
  92.     short                fEndOffset;
  93. };
  94.  
  95. //========================================================================================
  96. //    class CEditViewSelContent
  97. //========================================================================================
  98.  
  99. class CEditViewSelContent : public FW_CContent
  100. {
  101.   public:
  102.     FW_DECLARE_AUTO(CEditViewSelContent)
  103.     
  104.     CEditViewSelContent(Environment* ev, FW_CEditView* editview);
  105.     virtual ~CEditViewSelContent();
  106.  
  107.   public:
  108.     //------ FW_CContent API
  109.     virtual void        ExternalizeKind(Environment* ev,
  110.                                     ODStorageUnit* storageUnit,
  111.                                     FW_CKind* kind,
  112.                                     FW_StorageKinds storageKind,
  113.                                     FW_CPromise* promise,
  114.                                     FW_CCloneInfo* cloneInfo);
  115.     virtual FW_Boolean    InternalizeKind(Environment* ev,
  116.                                     ODStorageUnit* storageUnit, 
  117.                                     FW_CKind* kind,
  118.                                     FW_StorageKinds storageKind,
  119.                                     FW_CCloneInfo* cloneInfo);
  120.  
  121.     //------ New API
  122.     FW_CString             GetInternalizedText(Environment* ev);
  123.     void                 ClearSelectedText(Environment* ev);
  124.     void                 UnselectText(Environment* ev);
  125.     FW_Boolean             IsEmpty(Environment* ev) const;
  126.  
  127.   protected:
  128.     FW_CEditView*         fEditView;
  129.     FW_CString            fInternalizedText;    // holds text that was just internalized
  130. };
  131.  
  132. //----------------------------------------------------------------------------------------
  133. inline FW_CString CEditViewSelContent::GetInternalizedText(Environment*)
  134. {
  135.     return fInternalizedText;
  136. }
  137.  
  138. //========================================================================================
  139. //    class CEditViewSelection
  140. //========================================================================================
  141.  
  142. class CEditViewSelection : public FW_CSelection
  143. {
  144.   public:
  145.     FW_DECLARE_AUTO(CEditViewSelection)
  146.  
  147.     CEditViewSelection(Environment* ev, FW_CEditView* editview);
  148.     virtual ~CEditViewSelection();
  149.     
  150.   public:
  151.     virtual void            CloseSelection(Environment* ev);
  152.     virtual void            ClearSelection(Environment* ev);
  153.     virtual FW_Boolean        IsEmpty(Environment* ev) const;
  154.     virtual void            SelectAll(Environment* ev);
  155.  
  156.     virtual FW_CContent*    GetSelectedContent(Environment* ev);
  157.  
  158.   private:
  159.     CEditViewSelContent*    fSelectedContent;
  160. };
  161.  
  162. //========================================================================================
  163. // Prototypes
  164. //========================================================================================
  165.  
  166. FW_Boolean InternalizeText(Environment* ev, ODStorageUnit* storageUnit, 
  167.                                 FW_CString& textData, FW_ByteCount maxChars);
  168.  
  169. //========================================================================================
  170. //     Inlines
  171. //========================================================================================
  172.  
  173. //---------------------------------------------------------------------------------------------------
  174. //     CEditViewCommand
  175. //---------------------------------------------------------------------------------------------------
  176.  
  177. inline void CEditViewCommand::SetSelection(CEditViewSelection* selection)
  178. {
  179.     fSelection = selection;
  180.     fOwnsSelection = true;    // we can delete our own selection later
  181. }
  182.  
  183. inline CEditViewSelection* CEditViewCommand::GetSelection(Environment*) const
  184. {
  185.     return (CEditViewSelection*)fSelection;
  186. }
  187.  
  188. //---------------------------------------------------------------------------------------------------
  189. //     CEditViewSelection
  190. //---------------------------------------------------------------------------------------------------
  191.  
  192. inline FW_CContent* CEditViewSelection::GetSelectedContent(Environment*)
  193. {
  194.     return fSelectedContent;
  195. }
  196.  
  197. #endif
  198.